package com.wolfking.config;

import com.wolfking.converter.config.DynamicDataSourceContext;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

@Component
public class DynamicDataSourceContextHolder implements DynamicDataSourceContext {

    private final ThreadLocal<String> contextHolder = new ThreadLocal<>();

    public  void setDataSourceType(String dataSourceType) {
        if(StringUtils.isNotBlank(dataSourceType)) {
            contextHolder.set(dataSourceType);
        }
    }

    public  String getDataSourceType() {
        return contextHolder.get();
    }

    public  void clearDataSourceType() {
        contextHolder.remove();
    }

}
